<?php
/**
 * url接口
 * @author ran.ran
 */
namespace common\helper;

class UrlManager
{
    
    /**
     * 生成URl
     * @param string $domain 域名地址
     * @param string|array $params use a string to represent a route (e.g. `site/index`),
     * @return string
     */
    public static function createUrl($domain,$params){
        
        $params = (array) $params;
        $anchor = isset($params['#']) ? '#' . $params['#'] : '';
        unset($params['#'], $params['r']);
        
        $route = trim($params[0], '/');
        
        unset($params[0]);
        
        //检查地址是否美化。含有?r=
        if(strpos($domain, '?r=') === false) {
            if (!empty($params) && ($query = http_build_query($params)) !== '') {
                $route .= '?' . $query;
            }
        }  else {
            if (!empty($params) && ($query = http_build_query($params)) !== '') {
                $route .= '&' . $query;
            }
        }
        
        return $domain.$route;
    }
    
    
}

?>